<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<title>hsm-statechart: hsm/hsm_state.h File Reference</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
</script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { searchBox.OnSelectItem(0); });
</script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectlogo"><img alt="Logo" src="hsm-statechart.png"/></td>
  <td style="padding-left: 0.5em;">
   <div id="projectname">hsm-statechart
   &#160;<span id="projectnumber">0.5</span>
   </div>
   <div id="projectbrief">An easy to use hierarchical state machine for C and C++</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.1.1 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="pages.html"><span>Related&#160;Pages</span></a></li>
      <li><a href="annotated.html"><span>Data&#160;Structures</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
      <li>
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
      <li><a href="globals.html"><span>Globals</span></a></li>
    </ul>
  </div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
$(document).ready(function(){initNavTree('hsm__state_8h.html','');});
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Data Structures</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark">&#160;</span>Typedefs</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark">&#160;</span>Enumerations</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(7)"><span class="SelectionMark">&#160;</span>Macros</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(8)"><span class="SelectionMark">&#160;</span>Pages</a></div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="header">
  <div class="summary">
<a href="#nested-classes">Data Structures</a> &#124;
<a href="#define-members">Macros</a> &#124;
<a href="#typedef-members">Typedefs</a>  </div>
  <div class="headertitle">
<div class="title">hsm_state.h File Reference</div>  </div>
</div><!--header-->
<div class="contents">

<p>Macros and typedefs used for declaring states.  
<a href="#details">More...</a></p>

<p><a href="hsm__state_8h_source.html">Go to the source code of this file.</a></p>
<table class="memberdecls">
<tr class="heading"><td colspan="2"><h2><a name="nested-classes"></a>
Data Structures</h2></td></tr>
<tr class="memitem:structhsm__state__rec"><td class="memItemLeft" align="right" valign="top">struct &#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="hsm__state_8h.html#structhsm__state__rec">hsm_state_rec</a></td></tr>
<tr class="memdesc:structhsm__state__rec"><td class="mdescLeft">&#160;</td><td class="mdescRight">a state descriptor <a href="http://dev.ionous.net/2012/06/state-descriptors.html">http://dev.ionous.net/2012/06/state-descriptors.html</a>  <a href="hsm__state_8h.html#structhsm__state__rec">More...</a><br/></td></tr>
</table><table class="memberdecls">
<tr class="heading"><td colspan="2"><h2><a name="define-members"></a>
Macros</h2></td></tr>
<tr class="memitem:a13ea60f370fd7663153ad6d7fb7c73e1"><td class="memItemLeft" align="right" valign="top">#define&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="hsm__state_8h.html#a13ea60f370fd7663153ad6d7fb7c73e1">HSM_STATE</a>(state, parent, initial)</td></tr>
<tr class="memdesc:a13ea60f370fd7663153ad6d7fb7c73e1"><td class="mdescLeft">&#160;</td><td class="mdescRight">Macro for declaring a state.  <a href="#a13ea60f370fd7663153ad6d7fb7c73e1"></a><br/></td></tr>
<tr class="memitem:a0cb7e4f750bdd83a03d75df4714f2efa"><td class="memItemLeft" align="right" valign="top">#define&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="hsm__state_8h.html#a0cb7e4f750bdd83a03d75df4714f2efa">HSM_STATE_ENTER</a>(state, parent, initial)</td></tr>
<tr class="memdesc:a0cb7e4f750bdd83a03d75df4714f2efa"><td class="mdescLeft">&#160;</td><td class="mdescRight">Macro for declaring a state + enter callback.  <a href="#a0cb7e4f750bdd83a03d75df4714f2efa"></a><br/></td></tr>
<tr class="memitem:a3263608681f4ec0b1075cb3c9c0a9280"><td class="memItemLeft" align="right" valign="top">#define&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="hsm__state_8h.html#a3263608681f4ec0b1075cb3c9c0a9280">HSM_STATE_ENTERX</a>(state, parent, initial)</td></tr>
<tr class="memdesc:a3263608681f4ec0b1075cb3c9c0a9280"><td class="mdescLeft">&#160;</td><td class="mdescRight">Macro for declaring a state + enter and exit callbacks.  <a href="#a3263608681f4ec0b1075cb3c9c0a9280"></a><br/></td></tr>
<tr class="memitem:af67fed27704933cb81dffe693588cb14"><td class="memItemLeft" align="right" valign="top">#define&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="hsm__state_8h.html#af67fed27704933cb81dffe693588cb14">_HSM_STATE</a>(State, Parent, Process, Enter, Exit, Initial)</td></tr>
<tr class="memdesc:af67fed27704933cb81dffe693588cb14"><td class="mdescLeft">&#160;</td><td class="mdescRight">Verbose macro for declaring a state.  <a href="#af67fed27704933cb81dffe693588cb14"></a><br/></td></tr>
</table><table class="memberdecls">
<tr class="heading"><td colspan="2"><h2><a name="typedef-members"></a>
Typedefs</h2></td></tr>
<tr class="memitem:ae16cf40ef01c5e281d2fcb8bba8ac661"><td class="memItemLeft" align="right" valign="top">typedef <a class="el" href="hsm__forwards_8h.html#aaf8612f2e29f91153ebf2c076aa68030">hsm_state</a>(*&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="hsm__state_8h.html#ae16cf40ef01c5e281d2fcb8bba8ac661">hsm_callback_process_event</a> )(<a class="el" href="hsm__forwards_8h.html#aaed055d181b35182dc8c2830721dbdc9">hsm_status</a> status)</td></tr>
<tr class="memdesc:ae16cf40ef01c5e281d2fcb8bba8ac661"><td class="mdescLeft">&#160;</td><td class="mdescRight">A state's event handler callback.  <a href="#ae16cf40ef01c5e281d2fcb8bba8ac661"></a><br/></td></tr>
<tr class="memitem:af766d6e8715b04f423b490cc5a056bf1"><td class="memItemLeft" align="right" valign="top">typedef <a class="el" href="hsm__forwards_8h.html#aa0e37ff043d2dd5216cc762ca03046cb">hsm_context</a>(*&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="hsm__state_8h.html#af766d6e8715b04f423b490cc5a056bf1">hsm_callback_enter</a> )(<a class="el" href="hsm__forwards_8h.html#aaed055d181b35182dc8c2830721dbdc9">hsm_status</a> status)</td></tr>
<tr class="memdesc:af766d6e8715b04f423b490cc5a056bf1"><td class="mdescLeft">&#160;</td><td class="mdescRight">A state's enter callback.  <a href="#af766d6e8715b04f423b490cc5a056bf1"></a><br/></td></tr>
<tr class="memitem:a5a740484248abeee497979cbac897ac8"><td class="memItemLeft" align="right" valign="top">typedef void(*&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="hsm__state_8h.html#a5a740484248abeee497979cbac897ac8">hsm_callback_action</a> )(<a class="el" href="hsm__forwards_8h.html#aaed055d181b35182dc8c2830721dbdc9">hsm_status</a> status)</td></tr>
<tr class="memdesc:a5a740484248abeee497979cbac897ac8"><td class="mdescLeft">&#160;</td><td class="mdescRight">A state's action callback.  <a href="#a5a740484248abeee497979cbac897ac8"></a><br/></td></tr>
<tr class="memitem:a75bddc6c285b72e7c14b011150df5ef8"><td class="memItemLeft" align="right" valign="top">typedef hsm_bool(*&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="hsm__state_8h.html#a75bddc6c285b72e7c14b011150df5ef8">hsm_callback_guard</a> )(<a class="el" href="hsm__forwards_8h.html#aaed055d181b35182dc8c2830721dbdc9">hsm_status</a> status)</td></tr>
<tr class="memdesc:a75bddc6c285b72e7c14b011150df5ef8"><td class="mdescLeft">&#160;</td><td class="mdescRight">Guard callback.  <a href="#a75bddc6c285b72e7c14b011150df5ef8"></a><br/></td></tr>
<tr class="memitem:af4d0dd11f8eb4db16255bd0566e92ba4"><td class="memItemLeft" align="right" valign="top">typedef <a class="el" href="hsm__state_8h.html#a5a740484248abeee497979cbac897ac8">hsm_callback_action</a>&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="hsm__state_8h.html#af4d0dd11f8eb4db16255bd0566e92ba4">hsm_callback_exit</a></td></tr>
<tr class="memdesc:af4d0dd11f8eb4db16255bd0566e92ba4"><td class="mdescLeft">&#160;</td><td class="mdescRight">A state's exit callback.  <a href="#af4d0dd11f8eb4db16255bd0566e92ba4"></a><br/></td></tr>
</table>
<hr/><a name="details" id="details"></a><h2>Detailed Description</h2>
<div class="textblock"><p>Macros and typedefs used for declaring states. </p>

<p>Definition in file <a class="el" href="hsm__state_8h_source.html">hsm_state.h</a>.</p>
</div><hr/><h2>Data Structure Documentation</h2>
<a name="structhsm__state__rec" id="structhsm__state__rec"></a>
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">struct hsm_state_rec</td>
        </tr>
      </table>
</div><div class="memdoc">
<div class="textblock"><p>a state descriptor <a href="http://dev.ionous.net/2012/06/state-descriptors.html">http://dev.ionous.net/2012/06/state-descriptors.html</a> </p>

<p>Definition at line <a class="el" href="hsm__state_8h_source.html#l00085">85</a> of file <a class="el" href="hsm__state_8h_source.html">hsm_state.h</a>.</p>
</div><table class="fieldtable">
<tr><th colspan="3">Data Fields</th></tr>
<tr><td class="fieldtype">
<a class="anchor" id="a8f8f80d37794cde9472343e4487ba3eb"></a>const char *</td>
<td class="fieldname">
name</td>
<td class="fielddoc">
name of the state ( useful for debugging ) </td></tr>
<tr><td class="fieldtype">
<a class="anchor" id="a33029b0d2695fe40010884b199bd7546"></a><a class="el" href="hsm__state_8h.html#ae16cf40ef01c5e281d2fcb8bba8ac661">hsm_callback_process_event</a></td>
<td class="fieldname">
process</td>
<td class="fielddoc">
the state's event handler callback </td></tr>
<tr><td class="fieldtype">
<a class="anchor" id="aa6a1c3b1e97b0015afee5573fb3ddc78"></a><a class="el" href="hsm__state_8h.html#af766d6e8715b04f423b490cc5a056bf1">hsm_callback_enter</a></td>
<td class="fieldname">
enter</td>
<td class="fielddoc">
enter action handler </td></tr>
<tr><td class="fieldtype">
<a class="anchor" id="af28bc68a562cca87d34f862c6ba6d3d6"></a><a class="el" href="hsm__state_8h.html#af4d0dd11f8eb4db16255bd0566e92ba4">hsm_callback_exit</a></td>
<td class="fieldname">
exit</td>
<td class="fielddoc">
exit action handler </td></tr>
<tr><td class="fieldtype">
<a class="anchor" id="a74ac4b1f244bc97ba0c1daab6f76979b"></a><a class="el" href="hsm__forwards_8h.html#aaf8612f2e29f91153ebf2c076aa68030">hsm_state</a></td>
<td class="fieldname">
initial</td>
<td class="fielddoc">
default sub-state (if any) for this state </td></tr>
<tr><td class="fieldtype">
<a class="anchor" id="aa4980a3eab7184813f0cd0a98a201fcb"></a><a class="el" href="hsm__forwards_8h.html#aaf8612f2e29f91153ebf2c076aa68030">hsm_state</a></td>
<td class="fieldname">
parent</td>
<td class="fielddoc">
parent of this state </td></tr>
<tr><td class="fieldtype">
<a class="anchor" id="acb5ba97551079e0b072c62c21d784ac5"></a>int</td>
<td class="fieldname">
depth</td>
<td class="fielddoc">
distance to the root state this-&gt;depth = this-&gt;parent-&gt;depth+1; root most state's depth == 0 </td></tr>
</table>

</div>
</div>
<hr/><h2>Macro Definition Documentation</h2>
<a class="anchor" id="a13ea60f370fd7663153ad6d7fb7c73e1"></a>
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">#define HSM_STATE</td>
          <td>(</td>
          <td class="paramtype">&#160;</td>
          <td class="paramname">state, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">&#160;</td>
          <td class="paramname">parent, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">&#160;</td>
          <td class="paramname">initial&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Macro for declaring a state. </p>
<p>Requires: </p>
<ul>
<li>A event handler function: MyStateEvent</li>
</ul>
<div class="fragment"><div class="line"><span class="comment">/*</span></div>
<div class="line"><span class="comment"> * an example of using #HSM_STATE</span></div>
<div class="line"><span class="comment"> */</span></div>
<div class="line"><a class="code" href="hsm__state_8h.html#a13ea60f370fd7663153ad6d7fb7c73e1" title="Macro for declaring a state.">HSM_STATE</a>( MyState,     <span class="comment">// name of state</span></div>
<div class="line">            <a class="code" href="hsm__machine_8c.html#a1ba67e8e0edddad002d4f4c44d0e73db" title="Token state for use with the HSM_STATE macros to represent the outer most state.">HsmTopState</a>,<span class="comment">// parent state, or HsmTopState for no parent </span></div>
<div class="line">            0 );        <span class="comment">// initial state to enter</span></div>
<div class="line"></div>
<div class="line"><span class="comment">/*</span></div>
<div class="line"><span class="comment"> * event handler for the above HSM_STATE declaration</span></div>
<div class="line"><span class="comment"> */</span></div>
<div class="line"><a class="code" href="hsm__state_8h.html#structhsm__state__rec" title="a state descriptor http://dev.ionous.net/2012/06/state-descriptors.html">hsm_state</a> MyStateEvent( <a class="code" href="hsm__status_8h.html#structhsm__status__rec" title="Structure used for consolidating callback parameters.">hsm_status</a> status )</div>
<div class="line">{</div>
<div class="line">    <a class="code" href="hsm__state_8h.html#structhsm__state__rec" title="a state descriptor http://dev.ionous.net/2012/06/state-descriptors.html">hsm_state</a> ret= NULL; <span class="comment">// return NULL if unhandled, or</span></div>
<div class="line">                         <span class="comment">// HsmStateHandled(), or</span></div>
<div class="line">                         <span class="comment">// HsmStateError(), or</span></div>
<div class="line">                         <span class="comment">// HsmStateFinal(), or</span></div>
<div class="line">                         <span class="comment">// some other state declared by #HSM_STATE</span></div>
<div class="line">    <span class="keywordflow">return</span> ret;</div>
<div class="line">}</div>
</div><!-- fragment --><dl class="params"><dt>Parameters:</dt><dd>
  <table class="params">
    <tr><td class="paramname">state</td><td>User defined name for the state. </td></tr>
    <tr><td class="paramname">parent</td><td>HsmTopState or a previously declared user defined state name. </td></tr>
    <tr><td class="paramname">initial</td><td>First state this state should enter. can be NULL.</td></tr>
  </table>
  </dd>
</dl>
<dl class="section see"><dt>See also:</dt><dd><a class="el" href="hsm__state_8h.html#ae16cf40ef01c5e281d2fcb8bba8ac661" title="A state&#39;s event handler callback.">hsm_callback_process_event</a> </dd></dl>

<p>Definition at line <a class="el" href="hsm__state_8h_source.html#l00139">139</a> of file <a class="el" href="hsm__state_8h_source.html">hsm_state.h</a>.</p>

</div>
</div>
<a class="anchor" id="a0cb7e4f750bdd83a03d75df4714f2efa"></a>
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">#define HSM_STATE_ENTER</td>
          <td>(</td>
          <td class="paramtype">&#160;</td>
          <td class="paramname">state, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">&#160;</td>
          <td class="paramname">parent, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">&#160;</td>
          <td class="paramname">initial&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Macro for declaring a state + enter callback. </p>
<p>Requires: </p>
<ul>
<li>An event handler function: MyStateEvent </li>
<li>An entry function : MyStateEnter</li>
</ul>
<dl class="params"><dt>Parameters:</dt><dd>
  <table class="params">
    <tr><td class="paramname">state</td><td>User defined name for the state. </td></tr>
    <tr><td class="paramname">parent</td><td>a user defined state name, or HsmTopState. </td></tr>
    <tr><td class="paramname">initial</td><td>First state this state should enter. can be NULL.</td></tr>
  </table>
  </dd>
</dl>
<dl class="section see"><dt>See also:</dt><dd><a class="el" href="hsm__state_8h.html#af766d6e8715b04f423b490cc5a056bf1" title="A state&#39;s enter callback.">hsm_callback_enter</a>, <a class="el" href="hsm__state_8h.html#ae16cf40ef01c5e281d2fcb8bba8ac661" title="A state&#39;s event handler callback.">hsm_callback_process_event</a> </dd></dl>

<p>Definition at line <a class="el" href="hsm__state_8h_source.html#l00156">156</a> of file <a class="el" href="hsm__state_8h_source.html">hsm_state.h</a>.</p>

</div>
</div>
<a class="anchor" id="a3263608681f4ec0b1075cb3c9c0a9280"></a>
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">#define HSM_STATE_ENTERX</td>
          <td>(</td>
          <td class="paramtype">&#160;</td>
          <td class="paramname">state, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">&#160;</td>
          <td class="paramname">parent, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">&#160;</td>
          <td class="paramname">initial&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Macro for declaring a state + enter and exit callbacks. </p>
<p>Requires: </p>
<ul>
<li>An event handler function: MyStateEvent </li>
<li>An entry function : MyStateEnter </li>
<li>An exit function : MyStateExit</li>
</ul>
<dl class="params"><dt>Parameters:</dt><dd>
  <table class="params">
    <tr><td class="paramname">state</td><td>User defined name for the state. </td></tr>
    <tr><td class="paramname">parent</td><td>HsmTopState or a previously declared user defined state name. </td></tr>
    <tr><td class="paramname">initial</td><td>First state this state should enter. can be NULL.</td></tr>
  </table>
  </dd>
</dl>
<dl class="section see"><dt>See also:</dt><dd><a class="el" href="hsm__state_8h.html#af4d0dd11f8eb4db16255bd0566e92ba4" title="A state&#39;s exit callback.">hsm_callback_exit</a>, <a class="el" href="hsm__state_8h.html#af766d6e8715b04f423b490cc5a056bf1" title="A state&#39;s enter callback.">hsm_callback_enter</a>, <a class="el" href="hsm__state_8h.html#ae16cf40ef01c5e281d2fcb8bba8ac661" title="A state&#39;s event handler callback.">hsm_callback_process_event</a> </dd></dl>

<p>Definition at line <a class="el" href="hsm__state_8h_source.html#l00175">175</a> of file <a class="el" href="hsm__state_8h_source.html">hsm_state.h</a>.</p>

</div>
</div>
<a class="anchor" id="af67fed27704933cb81dffe693588cb14"></a>
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">#define _HSM_STATE</td>
          <td>(</td>
          <td class="paramtype">&#160;</td>
          <td class="paramname">State, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">&#160;</td>
          <td class="paramname">Parent, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">&#160;</td>
          <td class="paramname">Process, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">&#160;</td>
          <td class="paramname">Enter, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">&#160;</td>
          <td class="paramname">Exit, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">&#160;</td>
          <td class="paramname">Initial&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Verbose macro for declaring a state. </p>
<p>This macro is used by <a class="el" href="hsm__state_8h.html#a13ea60f370fd7663153ad6d7fb7c73e1" title="Macro for declaring a state.">HSM_STATE</a>, <a class="el" href="hsm__state_8h.html#a0cb7e4f750bdd83a03d75df4714f2efa" title="Macro for declaring a state + enter callback.">HSM_STATE_ENTER</a>, <a class="el" href="hsm__state_8h.html#a3263608681f4ec0b1075cb3c9c0a9280" title="Macro for declaring a state + enter and exit callbacks.">HSM_STATE_ENTERX</a>. </p>
<div class="fragment"><div class="line">Notes <span class="keywordflow">for</span> <a class="code" href="hsm__state_8h.html#a13ea60f370fd7663153ad6d7fb7c73e1" title="Macro for declaring a state.">HSM_STATE</a>:</div>
<div class="line"></div>
<div class="line">    The wrapper <span class="keywordflow">for</span> state() lets parent and child live in different translation units (.c files)</div>
<div class="line">    if all states were gauranteed to be in the same unit</div>
<div class="line">    depth could be a counter enum { <span class="keyword">enum</span> {State##Depth = Parent##Depth+`;} and data could be <span class="keyword">static</span>.</div>
<div class="line"></div>
<div class="line">    it might be possible to split the macro split into <span class="stringliteral">&#39;decl&#39;</span> and <span class="stringliteral">&#39;implement&#39;</span> sections</div>
<div class="line">    and create the same effect, but i think not without duplicating the parameters every usage</div>
<div class="line"></div>
<div class="line">    Additional notes <span class="keywordflow">for</span> Initial State:</div>
<div class="line"></div>
<div class="line">    The initial state uses two lookup functions to ensure a valid name when initial= 0</div>
<div class="line">    and to enable link time checking that the initial state is a child of parent.</div>
<div class="line"></div>
<div class="line">for any given macro expansion the definitions are:</div>
<div class="line"></div>
<div class="line">    State##Lookup##Initial: forward declares, but doesn<span class="stringliteral">&#39;t implement.</span></div>
<div class="line"><span class="stringliteral">    Parent##Lookup##State : implements this in case our parent wants us as its initial state.</span></div>
<div class="line"><span class="stringliteral">    State##Lookup##0      : returns 0.</span></div>
<div class="line"><span class="stringliteral"></span></div>
<div class="line"><span class="stringliteral">so, for two these two states:</span></div>
<div class="line"><span class="stringliteral"></span></div>
<div class="line"><span class="stringliteral">    HSM_STATE( Outer, Top, Inner );</span></div>
<div class="line"><span class="stringliteral">     HSM_State( Inner, Outer, 0 );</span></div>
<div class="line"><span class="stringliteral"></span></div>
<div class="line"><span class="stringliteral">we get these this sequence of declarations:</span></div>
<div class="line"><span class="stringliteral"></span></div>
<div class="line"><span class="stringliteral">     state outer:</span></div>
<div class="line"><span class="stringliteral">        OuterLookupInner();                  &lt;--- declared, defined later; this is the initial we want.</span></div>
<div class="line"><span class="stringliteral">        OuterLookup0() { return 0; }         &lt;--- unused, most linkers will optimize</span></div>
<div class="line"><span class="stringliteral">        Outer() {</span></div>
<div class="line"><span class="stringliteral">          initial= OuterLookupInner();       &lt;--- if inner isn&#39;</span>t a child of outer, linker complains</div>
<div class="line">        }</div>
<div class="line">        TopLookupOuter() { <span class="keywordflow">return</span> Outer; }   &lt;--- unused, most linkers will optimize</div>
<div class="line"></div>
<div class="line">     state inner:</div>
<div class="line">        InnerLookup0();                      &lt;--- <span class="keyword">this</span> is the initial we want</div>
<div class="line">        InnerLookup0() { <span class="keywordflow">return</span> 0; }         &lt;--- and the standard implementation</div>
<div class="line">        Inner() {</div>
<div class="line">           initial= InnerLookup0();          &lt;--- meaning we don<span class="stringliteral">&#39;t get an initial state.</span></div>
<div class="line"><span class="stringliteral">        }</span></div>
<div class="line"><span class="stringliteral">        OuterLookupInner() { return Inner; } &lt;--- inneris* a child of outer, this proves it.</span></div>
</div><!-- fragment --><dl class="params"><dt>Parameters:</dt><dd>
  <table class="params">
    <tr><td class="paramname">State</td><td>User defined name for the state. </td></tr>
    <tr><td class="paramname">Parent</td><td>A user defined state name, or HsmTopState. </td></tr>
    <tr><td class="paramname">Process</td><td>Event handler function. </td></tr>
    <tr><td class="paramname">Enter</td><td>Function to call on state enter. </td></tr>
    <tr><td class="paramname">Exit</td><td>Function to call on state exit. </td></tr>
    <tr><td class="paramname">Initial</td><td>Initial state for this state to enter, or 0. </td></tr>
  </table>
  </dd>
</dl>

<p>Definition at line <a class="el" href="hsm__state_8h_source.html#l00193">193</a> of file <a class="el" href="hsm__state_8h_source.html">hsm_state.h</a>.</p>

</div>
</div>
<hr/><h2>Typedef Documentation</h2>
<a class="anchor" id="ae16cf40ef01c5e281d2fcb8bba8ac661"></a>
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">typedef <a class="el" href="hsm__forwards_8h.html#aaf8612f2e29f91153ebf2c076aa68030">hsm_state</a>(* hsm_callback_process_event)(<a class="el" href="hsm__forwards_8h.html#aaed055d181b35182dc8c2830721dbdc9">hsm_status</a> status)</td>
        </tr>
      </table>
</div><div class="memdoc">

<p>A state's event handler callback. </p>
<p>A function of this signature is required for every state declared via <a class="el" href="hsm__state_8h.html#a13ea60f370fd7663153ad6d7fb7c73e1" title="Macro for declaring a state.">HSM_STATE</a>.</p>
<dl class="params"><dt>Parameters:</dt><dd>
  <table class="params">
    <tr><td class="paramname">status</td><td>Current state of the machine. </td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns:</dt><dd>NULL, a state to transition to, or a predefined state token.</dd></dl>
<dl class="section note"><dt>Note:</dt><dd>You should return NULL from an event handler by default to indicate the event was not handled. To transition to a new state, return the name of the new state as previously declared via a <a class="el" href="hsm__state_8h.html#a13ea60f370fd7663153ad6d7fb7c73e1" title="Macro for declaring a state.">HSM_STATE</a> macro. To indicate an event has been handled, but no transition is required: you should return <a class="el" href="hsm__machine_8h.html#a3a16509f8bea2bca3f7b3f36525cc243" title="Token state that can be used by event handler functions to indicate the event was handled and no furt...">HsmStateHandled()</a>. Returning <a class="el" href="hsm__machine_8h.html#a5574ce97f59edf4b77fafabc6ea36e54" title="Token state for when a machine has inadvertently killed itself.">HsmStateError()</a> indicates a critical error has occured and the statemachine can no longer function. Returning <a class="el" href="hsm__machine_8h.html#a385e51689fbbf6376b00a27029b7f79a" title="A machine in a final state has deliberately killed itself.">HsmStateFinal()</a> indicates the statemachine has terminated and event callbacks are no longer desired. </dd></dl>

<p>Definition at line <a class="el" href="hsm__state_8h_source.html#l00032">32</a> of file <a class="el" href="hsm__state_8h_source.html">hsm_state.h</a>.</p>

</div>
</div>
<a class="anchor" id="af766d6e8715b04f423b490cc5a056bf1"></a>
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">typedef <a class="el" href="hsm__forwards_8h.html#aa0e37ff043d2dd5216cc762ca03046cb">hsm_context</a>(* hsm_callback_enter)(<a class="el" href="hsm__forwards_8h.html#aaed055d181b35182dc8c2830721dbdc9">hsm_status</a> status)</td>
        </tr>
      </table>
</div><div class="memdoc">

<p>A state's enter callback. </p>
<p>A function of this signature is required for every state declared via <a class="el" href="hsm__state_8h.html#a0cb7e4f750bdd83a03d75df4714f2efa" title="Macro for declaring a state + enter callback.">HSM_STATE_ENTER</a>.</p>
<dl class="params"><dt>Parameters:</dt><dd>
  <table class="params">
    <tr><td class="paramname">status</td><td>Current state of the machine. The context member of the status is either the parent state's <a class="el" href="hsm__state_8h.html#af766d6e8715b04f423b490cc5a056bf1" title="A state&#39;s enter callback.">hsm_callback_enter</a>, or if no parent state: the context passed to <a class="el" href="hsm__machine_8c.html#ac3c05a1d7215bdf5f9e4132a26dafca2" title="Initialize a statemachine with a context stack to its default values.">HsmMachineWithContext()</a>.</td></tr>
    <tr><td class="paramname">evt</td><td>The <a class="el" href="hsm__forwards_8h.html#ab8e8ab8d2eb97eb5cc6331d85262fb76" title="Pointer to an hsm_event_rec.">hsm_event</a> that needs handling.</td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns:</dt><dd>Optionally: a new <a class="el" href="hsm__context_8h.html#structhsm__context__rec" title="A per state instance context object.">hsm_context_rec</a>. The context will be passed to all subsequent calls to the state's <a class="el" href="hsm__state_8h.html#ae16cf40ef01c5e281d2fcb8bba8ac661" title="A state&#39;s event handler callback.">hsm_callback_process_event</a> and the state's <a class="el" href="hsm__state_8h.html#af4d0dd11f8eb4db16255bd0566e92ba4" title="A state&#39;s exit callback.">hsm_callback_exit</a>.</dd></dl>
<dl class="section note"><dt>Note:</dt><dd>The return value must not be null if the status.ctx was not null. Returning null when status.ctx is valid indicates a critical error has occured. ex. enter could not allocate context memory </dd></dl>

<p>Definition at line <a class="el" href="hsm__state_8h_source.html#l00052">52</a> of file <a class="el" href="hsm__state_8h_source.html">hsm_state.h</a>.</p>

</div>
</div>
<a class="anchor" id="a5a740484248abeee497979cbac897ac8"></a>
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">typedef void(* hsm_callback_action)(<a class="el" href="hsm__forwards_8h.html#aaed055d181b35182dc8c2830721dbdc9">hsm_status</a> status)</td>
        </tr>
      </table>
</div><div class="memdoc">

<p>A state's action callback. </p>
<p>Also used for exit actions.</p>
<dl class="params"><dt>Parameters:</dt><dd>
  <table class="params">
    <tr><td class="paramname">status</td><td>Current state of the machine. </td></tr>
  </table>
  </dd>
</dl>

<p>Definition at line <a class="el" href="hsm__state_8h_source.html#l00060">60</a> of file <a class="el" href="hsm__state_8h_source.html">hsm_state.h</a>.</p>

</div>
</div>
<a class="anchor" id="a75bddc6c285b72e7c14b011150df5ef8"></a>
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">typedef hsm_bool(* hsm_callback_guard)(<a class="el" href="hsm__forwards_8h.html#aaed055d181b35182dc8c2830721dbdc9">hsm_status</a> status)</td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Guard callback. </p>
<dl class="params"><dt>Parameters:</dt><dd>
  <table class="params">
    <tr><td class="paramname">status</td><td>Current state of the machine. </td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns:</dt><dd>Return <a class="el" href="hsm__types_8h.html#ae231908aca4879403ae108cf0f5c7a9c" title="1">HSM_TRUE</a> if the guard passes and the transition,actions should be handled; <a class="el" href="hsm__types_8h.html#a661d07d1e0324624dd94942951801df4" title="0">HSM_FALSE</a> if the guard filters the transition,actions. </dd></dl>

<p>Definition at line <a class="el" href="hsm__state_8h_source.html#l00068">68</a> of file <a class="el" href="hsm__state_8h_source.html">hsm_state.h</a>.</p>

</div>
</div>
<a class="anchor" id="af4d0dd11f8eb4db16255bd0566e92ba4"></a>
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">typedef <a class="el" href="hsm__state_8h.html#a5a740484248abeee497979cbac897ac8">hsm_callback_action</a> <a class="el" href="hsm__state_8h.html#af4d0dd11f8eb4db16255bd0566e92ba4">hsm_callback_exit</a></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>A state's exit callback. </p>
<dl class="params"><dt>Parameters:</dt><dd>
  <table class="params">
    <tr><td class="paramname">status</td><td>Current state of the machine. </td></tr>
  </table>
  </dd>
</dl>

<p>Definition at line <a class="el" href="hsm__state_8h_source.html#l00075">75</a> of file <a class="el" href="hsm__state_8h_source.html">hsm_state.h</a>.</p>

</div>
</div>
</div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  <ul>
    <li class="navelem"><a class="el" href="dir_6c36b64852547327283732128225c9d7.html">hsm</a></li><li class="navelem"><a class="el" href="hsm__state_8h.html">hsm_state.h</a></li>
    <li class="footer">Generated on Sat Jul 7 2012 22:48:11 for hsm-statechart by
    <a href="http://www.doxygen.org/index.html">
    <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.1.1 </li>
  </ul>
</div>
</body>
</html>
